//
//  HeaderView.m
//  Moment
//
//  Created by dllo on 15/12/22.
//  Copyright © 2015年 谭泽源. All rights reserved.
//

#import "HeaderView.h"


@interface HeaderView ()

@property (nonatomic, strong) UIImageView *headImageView;   /**< 头像图片 */
@property (nonatomic, strong) UILabel *loginLabel;        /**< 登陆按钮 */
@property (nonatomic, strong) UIButton *searchButton;


@end

@implementation HeaderView


-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews
{
    //self.backgroundColor = [UIColor colorWithRed:0.22 green:0.22 blue:0.22 alpha:1];
    
    self.backgroundColor = [UIColor colorWithRed:0.454 green:0.484 blue:0.492 alpha:1.000];
    // 头像
    self.headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.height / 15, self.frame.size.height / 8.25, self.frame.size.height / 3.3, self.frame.size.height / 3.3)];
    self.headImageView.image = [UIImage imageNamed:@"iconfont-touxiang.png"];
    //裁掉边框
    self.headImageView.layer.masksToBounds = YES;
    //设置半径
    self.headImageView.layer.cornerRadius = self.headImageView.frame.size.width / 2;
    self.headImageView.layer.borderWidth = 0;
    self.headImageView.layer.borderColor = [UIColor clearColor].CGColor;
    [self addSubview:self.headImageView];
    
    
    self.loginLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.headImageView.frame.origin.x + self.headImageView.frame.size.width + self.frame.size.height / 16.5, self.headImageView.frame.origin.y + self.frame.size.height / 11, self.frame.size.width / 2, self.frame.size.height / 8.25)];
    self.loginLabel.text = @"游客7543125";
    self.loginLabel.textColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
    [self addSubview:self.loginLabel];
    
    self.searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.searchButton.frame = CGRectMake(self.headImageView.frame.origin.x + self.frame.size.height / 9, self.headImageView.frame.origin.y + self.headImageView.frame.size.height + self.frame.size.height / 5, self.frame.size.width - 4 * (self.headImageView.frame.origin.x + self.frame.size.height / 11), self.frame.size.height / 4.5);
    self.searchButton.backgroundColor = [UIColor colorWithRed:0.37 green:0.37 blue:0.37 alpha:1];
    self.searchButton.layer.masksToBounds = YES;
    self.searchButton.layer.cornerRadius = self.searchButton.frame.size.height / 2;
    self.searchButton.layer.borderWidth = 0;
    self.searchButton.layer.borderColor = [UIColor clearColor].CGColor;
    [self.searchButton addTarget:self action:@selector(searchButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.searchButton];
    
    UIImageView *searchImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.searchButton.frame.origin.x + self.searchButton.frame.size.height / 4, self.searchButton.frame.origin.y + self.searchButton.frame.size.height / 5, self.searchButton.frame.size.height - 2 * self.searchButton.frame.size.height / 5, self.searchButton.frame.size.height - 2 * self.searchButton.frame.size.height / 5)];
    searchImageView.image = [UIImage imageNamed:@"iconfont-fangdajing.png"];
    [self addSubview:searchImageView];
}


- (void)searchButtonAction:(UIButton *)searchButton
{
    [self.SearchDelegate pushToPZRSearchViewController];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
